package com.hqyj.onlineExamination.modules.exam.controller;

import com.hqyj.onlineExamination.modules.common.entity.ResultEntity;
import com.hqyj.onlineExamination.modules.common.entity.SearchBean;
import com.hqyj.onlineExamination.modules.exam.service.PaperService;
import com.hqyj.onlineExamination.modules.exam.service.QuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

import com.github.pagehelper.PageInfo;

import com.hqyj.onlineExamination.modules.exam.entity.Paper;
import org.springframework.web.bind.annotation.*;

// 试卷页
@RestController
@RequestMapping("/api")
public class PaperController {

    @Autowired
    private PaperService paperService;

    /**
     * 127.0.0.1:81/api/paper/v1/1 ---- get
     */
    @GetMapping("/paper/v1/{id}")
    Paper getPaperById(@PathVariable int id) {
        return paperService.getPaperById(id);
    }

    /**
     * 127.0.0.1:81/api/paper/v2/Java_SE_test_admin ---- get
     */
    @GetMapping("/paper/v2/{subject}")
    Paper getPaperBySubject(@PathVariable String subject) {
        return paperService.getPaperBySubject(subject);
    }

    /**
     * 127.0.0.1:81/api/paper ---- post
     * {"subject":"aaa", "totalTime":"60", "totalScore":"100"}
     */
    @PostMapping(value = "/paper", consumes = "application/json")
    ResultEntity<Paper> insertPaper(@RequestBody Paper paper) {
        return paperService.insertPaper(paper);
    }

    /**
     * 127.0.0.1:81/api/paper ---- put
     * {"id":"8", "totalTime":"60", "totalScore":"100"}
     */
    @PutMapping(value = "/paper", consumes = "application/json")
    ResultEntity<Paper> updatePaper(@RequestBody Paper paper) {
        return paperService.updatePaper(paper);
    }

    /**
     * 127.0.0.1:81/api/paper/8 ---- delete
     */
    @DeleteMapping("/paper/{id}")
    ResultEntity<Paper> deletePaperById(@PathVariable int id) {
        return paperService.deletePaperById(id);
    }

    /**
     * 127.0.0.1:81/api/papers ---- Post
     * {"currentPage":"1","pageSize":"5","orderBy":"id","direction":"asc","keyWord":""}
     */
    @PostMapping(value = "/papers", consumes = "application/json")
    PageInfo<Paper> getPapersBySearchBean(@RequestBody SearchBean searchBean) {
        return paperService.getPapersBySearchBean(searchBean);
    }

    @GetMapping("/paper/{id}")
    public ResultEntity<Map<String,Object>> getAllPaperById(@PathVariable int id) {
        return paperService.getAllPaperById(id);
    }
}
